package com.atguigu.gmall.activity.redis;
import com.github.benmanes.caffeine.cache.Cache;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
@SuppressWarnings("all")
public class MessageReceive {

    @Autowired
    private Cache<String,String> seckillCache;

    /**
     * 监听redis话题中消息:消费者
     * @param state
     */
    public void receiveSeckillGoodState(String state){
        if(StringUtils.isNotBlank(state)){
            log.info("监听到秒杀消息:" + state);
            state = state.replace("\"","");

            //将秒杀商品放入本地缓存中
            String[] split = state.split(":");
            if(split != null & split.length == 2){
                seckillCache.put(split[0],split[1]);
            }
        }
    }
}